package net.towee.client.gadgets;

import java.util.HashMap;
import java.util.Map;

import com.google.common.base.Preconditions;

/**
 * This class contains static methods for gettina available gadgets.
 * 
 * @author c58
 */
public class GadgetsHolder {
	// List of available gadgets
	private final static Map<String, GadgetInfo> gadgets = new HashMap<String, GadgetInfo>();

	/**
	 * Add gadget to gadgets list
	 * 
	 * @param gadget
	 */
	public static void addGadget(GadgetInfo gadget) {
		Preconditions.checkArgument(!gadgets.containsKey(gadget.getCanonicalName()),
				"gadget " + gadget.getCanonicalName() + " already not exists");
		gadgets.put(gadget.getCanonicalName(), gadget);
	}

	/**
	 * Return GadgetInfo object of gadget with given canonical name.
	 * 
	 * @param name
	 * @return
	 */
	public static GadgetInfo getGadgetByCanonicalName(String name) {
		Preconditions.checkArgument(gadgets.containsKey(name), "gadget " + name + " not exists");
		return gadgets.get(name);
	}

	/**
	 * Return list of available gadgets
	 * 
	 * @return
	 */
	public static Iterable<GadgetInfo> getGadgetsList() {
		return gadgets.values();
	}
}
